const domain = 'https://yhj003.cn'
class Request {
  /**
   * get 请求
   * @param {*} param0
   * @returns 返回promise
   */
 static get({ url,timeout=20000, data, ...config }) {
    return new Promise((resolve, reject) => {
      wx.request({
        url: domain + url,
        method: "GET",
        timeout:timeout,
        success(res) {
          console.log('请求成功',res.data);
          resolve(res.data);
        },
        fail(error) {
          console.error('请求失败',error);
          reject(error);
        },
      });
    });
  }

   /**
   * post请求
   * @param {*} param0
   * @returns 返回promise
   */
 static post({ url, data,timeout=20000, header='application/json', ...config }) {
    return new Promise((resolve, reject) => {
      wx.request({
        url: domain + url,
        data: data,
        timeout:timeout,
        header:header,
        method: "POST",
        success(res) {
          console.log('请求成功',res.data);
          resolve(res.data);
        },
        fail(error) {
          console.error('请求失败:',error);
          reject(error);
        },
      });
    });
  }
}

export default Request;
